package clusteringTest;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.HashMap;
//import java.util.Iterator;
//import java.util.Set;


/**
 * RemoveStopWord
 * input:wordA wordB wordC
 * output:wordA wordC 
 * 
 *          RemoveStopWord rs =new RemoveStopWord();
 *           rs.RemoveStop(wordA wordB wordC);
 *           
 * @author DXL
 * @version 1.0, 26/2/2011
 */

public class RemoveStopWord {

	   public static HashMap<String, Double> hm_1 = new HashMap<String, Double>();
	   
	   
	  public  RemoveStopWord()
	   {
		  try
		  {
			  File file = new File("/home/tuxinhui/workspace/analyzer/StopWords.txt");
			  
			   BufferedReader br =new BufferedReader(new InputStreamReader(new FileInputStream(file), "GBK"));
			   String word = "";
			   for(word = br.readLine(); word != null; word = br.readLine())
			   {
				 // System.out.print(word);
				   hm_1.put(word , 0.5);
			   }
		  }
		  catch(Exception e)
		  {
			  e.printStackTrace();
		  }
	   }
	   
	   
	   public String RemoveStop(String str)
	   {
		   StringBuffer sb = new StringBuffer();
		   
	     	//	System.out.println("test "+str);
	     		String[] split = str.split(" ");
	     		
	     		for(int i=0;i<split.length;i++)
	     		{
	     			String temp = split[i];
		    	      if (!hm_1.containsKey(temp))
		    	    	  {
		    	    	  sb.append(temp);
		    	    	  sb.append(" ");
		    	    	  }
	     		}//for
	     	 String	result = sb.toString().trim();
	     	//	hm_1.clear();
	    	return result; 
	   }
	   
	   public static void main(String args[])
	   {
		   RemoveStopWord rw = new RemoveStopWord();
	       long start= new Date().getTime();
		   String str = "开启 邮箱 开启 一天 的 愉快";
		   System.out.println(rw.RemoveStop(str));
		   long end = new Date().getTime();
		   float cost_time = (float)(end - start)/1000 ;
		   System.out.println( cost_time );
	   }
}
